import 'dart:convert';

import '../../../gyms/gyms_page/models/gym.dart';
import '../../sports_page/models/sport.dart';

GymSport gymSportFromJson(String str) => GymSport.fromJson(json.decode(str));

String gymSportToJson(GymSport data) => json.encode(data.toJson());

class GymSport {
  final int gymSportId;
  final int gymId;
  final int sportId;
  final int active;
  final int isDeleted;
  final int createdBy;
  final int? updatedBy;
  final int? deletedBy;
  final DateTime createAt;
  final DateTime updateAt;
  final DateTime? deletedAt;
  final Sport sport;
  final Gym gym;

  GymSport({
    this.gymSportId = -1,
    required this.gymId,
    required this.sportId,
    required this.active,
    required this.isDeleted,
    required this.createdBy,
    this.updatedBy,
    this.deletedBy,
    required this.createAt,
    required this.updateAt,
    this.deletedAt,
    required this.sport,
    required this.gym,
  });

  GymSport copyWith({
    int? gymSportId,
    int? gymId,
    int? sportId,
    int? active,
    int? isDeleted,
    int? createdBy,
    dynamic updatedBy,
    dynamic deletedBy,
    DateTime? createAt,
    DateTime? updateAt,
    dynamic deletedAt,
    Sport? sport,
    Gym? gym,
  }) =>
      GymSport(
        gymSportId: gymSportId ?? this.gymSportId,
        gymId: gymId ?? this.gymId,
        sportId: sportId ?? this.sportId,
        active: active ?? this.active,
        isDeleted: isDeleted ?? this.isDeleted,
        createdBy: createdBy ?? this.createdBy,
        updatedBy: updatedBy ?? this.updatedBy,
        deletedBy: deletedBy ?? this.deletedBy,
        createAt: createAt ?? this.createAt,
        updateAt: updateAt ?? this.updateAt,
        deletedAt: deletedAt ?? this.deletedAt,
        sport: sport ?? this.sport,
        gym: gym ?? this.gym,
      );

  factory GymSport.fromJson(Map<String, dynamic> json) => GymSport(
    gymSportId: json["gym_sport_id"],
    gymId: json["gym_id"],
    sportId: json["sport_id"],
    active: json["active"],
    isDeleted: json["is_deleted"],
    createdBy: json["created_by"],
    updatedBy: json["updated_by"],
    deletedBy: json["deleted_by"],
    createAt: DateTime.parse(json["create_at"]),
    updateAt: DateTime.parse(json["update_at"]),
    deletedAt: DateTime.tryParse(json["deleted_at"].toString()),
    sport: Sport.fromJson(json["sport"]),
    gym: Gym.fromJson(json["gym"]),
  );

  Map<String, dynamic> toJson() => {
    "gym_sport_id": gymSportId,
    "gym_id": gymId,
    "sport_id": sportId,
    "active": active,
    "is_deleted": isDeleted,
    "created_by": createdBy,
    "updated_by": updatedBy,
    "deleted_by": deletedBy,
    "create_at": createAt.toIso8601String(),
    "update_at": updateAt.toIso8601String(),
    "deleted_at": deletedAt,
    "sport": sport.toJson(),
    "gym": gym.toJson(),
  };
}